import java.util.ArrayList;
import java.util.*;

/*
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
public class Solution {

    ArrayList<ArrayList<Integer> > Print(TreeNode pRoot) {
        
        ArrayList<ArrayList<Integer>> ret = new ArrayList<>();

        if (pRoot == null)
            return ret;

        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(pRoot);

        boolean flag = true;

        while (!queue.isEmpty()) {
            int size = queue.size();
            ArrayList<Integer> row = new ArrayList<>();
            while (size-- > 0) {
                TreeNode node = queue.remove();

                if (flag) 
                    row.add(node.val);
                else 
                    row.add(0, node.val);

                if (node.left != null)
                    queue.add(node.left);
                if (node.right != null)
                    queue.add(node.right);
            }
            flag = !flag;
            System.out.println(flag);
            ret.add(row);
        }

        return ret;

    }
}
